﻿using System.Collections.Generic;
using System.Windows.Media;
using OpenLS.Spreadsheet.Formats.Biff.Records;

namespace OpenLS.Spreadsheet.Formats.Biff
{
    class BuiltinPalette: SinglePalette
    {
        public BuiltinPalette() : base(items)
        {
        }

        protected static IEnumerable<Pair<int, Color>> items
        {
            get
            {
                yield return i(FontRecord.BlackColorIndex, Colors.Black);
                yield return i(0x00,
                               Colors.Black);
                yield return i( 0x01,
                                Colors.White);
                yield return i(0x02,
                               Colors.Red);
                yield return i(0x03,
                               Colors.Green);
                yield return i(0x04,
                               Colors.Blue);
                yield return i(0x05,
                               Colors.Yellow);
                yield return i(0x06,
                               Colors.Magenta);
                yield return i(0x07,
                               Colors.Cyan);
                yield return i(0x08,
                               Colors.Black);
                yield return i(0x09,
                               Colors.White);
                yield return i(0x0A,
                               Color.FromRgb(0xFF, 0x00, 0x00));
                yield return i(0x0B,
                               Color.FromRgb(0x00, 0xFF, 0x00));
                yield return i(0x0C,
                               Color.FromRgb(0x00, 0x00, 0xFF));
                yield return i(0x0D,
                               Color.FromRgb(0xFF, 0xFF, 0x00));
                yield return i(0x0E,
                               Color.FromRgb(0xFF, 0x00, 0xFF));
                yield return i(0x0F,
                               Color.FromRgb(0x00, 0xFF, 0xFF));

                yield return i(0x10,
                               Color.FromRgb(0x80, 0x00, 0x00));
                yield return i(0x11,
                               Color.FromRgb(0x00, 0x80, 0x00));
                yield return i(0x12,
                               Color.FromRgb(0x00, 0x00, 0x80));
                yield return i(0x13,
                               Color.FromRgb(0x80, 0x80, 0x00));                
                yield return i(0x14,
                               Color.FromRgb(0x80, 0x00, 0x80));
                yield return i(0x15,
                               Color.FromRgb(0x00, 0x80, 0x80));
                yield return i(0x16,
                               Color.FromRgb(0xC0, 0xC0, 0xC0));
                yield return i(0x17,
                               Color.FromRgb(0x80, 0x80, 0x80));
                yield return i(0x18,
                               Color.FromRgb(0x99, 0x99, 0xFF));
                yield return i(0x19,
                               Color.FromRgb(0x99, 0x33, 0x66));
                yield return i(0x1A,
                               Color.FromRgb(0xFF, 0xFF, 0xCC));
                yield return i(0x1B,
                               Color.FromRgb(0xCC, 0xFF, 0xFF));
                yield return i(0x1C,
                               Color.FromRgb(0x66, 0x00, 0x66));
                yield return i(0x1D,
                               Color.FromRgb(0xFF, 0x80, 0x80));
                yield return i(0x1E,
                               Color.FromRgb(0x00, 0x66, 0xCC));
                yield return i(0x1F,
                               Color.FromRgb(0xCC, 0xCC, 0xFF));
                
                yield return i(0x20,
                               Color.FromRgb(0x00, 0x00, 0x80));
                yield return i(0x21,
                               Color.FromRgb(0xFF, 0x00, 0xFF));
                yield return i(0x22,
                               Color.FromRgb(0xFF, 0xFF, 0x00));
                yield return i(0x23,
                               Color.FromRgb(0x00, 0xFF, 0xFF));
                yield return i(0x24,
                               Color.FromRgb(0x80, 0x00, 0x80));
                yield return i(0x25,
                               Color.FromRgb(0x80, 0x00, 0x00));
                yield return i(0x26,
                               Color.FromRgb(0x00, 0x80, 0x80));
                yield return i(0x27,
                               Color.FromRgb(0x00, 0x00, 0xFF));
                yield return i(0x28,
                               Color.FromRgb(0x00, 0xCC, 0xFF));
                yield return i(0x29,
                               Color.FromRgb(0xCC, 0xFF, 0xFF));
                yield return i(0x2A,
                               Color.FromRgb(0xCC, 0xFF, 0xCC));
                yield return i(0x2B,
                               Color.FromRgb(0xFF, 0xFF, 0x99));
                yield return i(0x2C,
                               Color.FromRgb(0x99, 0xCC, 0xFF));
                yield return i(0x2D,
                               Color.FromRgb(0xFF, 0x99, 0xCC));
                yield return i(0x2E,
                               Color.FromRgb(0xCC, 0x99, 0xFF));
                yield return i(0x2F,
                               Color.FromRgb(0xFF, 0xCC, 0x99));


                yield return i(0x30,
                               Color.FromRgb(0x33, 0x66, 0xFF));
                yield return i(0x31,
                               Color.FromRgb(0x33, 0xCC, 0xCC));
                yield return i(0x32,
                               Color.FromRgb(0x99, 0xCC, 0x00));
                yield return i(0x33,
                               Color.FromRgb(0xFF, 0xCC, 0x00));
                yield return i(0x34,
                               Color.FromRgb(0xFF, 0x99, 0x00));
                yield return i(0x35,
                               Color.FromRgb(0xFF, 0x66, 0x00));
                yield return i(0x36,
                               Color.FromRgb(0x66, 0x66, 0x99));
                yield return i(0x37,
                               Color.FromRgb(0x96, 0x96, 0x96));
                yield return i(0x38,
                               Color.FromRgb(0x00, 0x33, 0x66));
                yield return i(0x39,
                               Color.FromRgb(0x33, 0x99, 0x66));
                yield return i(0x3A,
                               Color.FromRgb(0x00, 0x33, 0x00));
                yield return i(0x3B,
                               Color.FromRgb(0x33, 0x33, 0x00));
                yield return i(0x3C,
                               Color.FromRgb(0x99, 0x33, 0x00));
                yield return i(0x3D,
                               Color.FromRgb(0x99, 0x33, 0x66));
                yield return i(0x3E,
                               Color.FromRgb(0x33, 0x33, 0x99));
                yield return i(0x3F,
                               Color.FromRgb(0x33, 0x33, 0x33));

            }
        }

        private static Pair<int, Color> i(int blackColorIndex, Color black)
        {
            return new Pair<int, Color>(blackColorIndex, black);
        }
    }
}